<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // localStorage存储数据
    localStorage.setItem('name', '张三');
    // 获取数据
    const name = localStorage.getItem('name');
    console.log(name);
    // 删除数据
    // localStorage.removeItem('name');

    // 存储对象
    const obj = {
      name: '张三',
      age: 18
    };
    localStorage.setItem('obj', JSON.stringify(obj));
    console.log(JSON.parse(localStorage.getItem('obj')));
    // 存储数组
    const arr = [1, 2, 3, 4, 5];
    localStorage.setItem('arr', JSON.stringify(arr));
    console.log(JSON.parse(localStorage.getItem('arr')));

    // sessionStorage存储数据
    sessionStorage.setItem('age', 18);
    // 获取数据
    const age = sessionStorage.getItem('age');
    console.log(age);
    // 删除数据
    // sessionStorage.removeItem('name');
  </script>
</body>
</html>